package net.guerlab.ucenter.client.handle;

import java.util.HashMap;
import java.util.Map;

import net.guerlab.ucenter.client.entity.Config;

public class ClientHandleCreater {

    private ClientAction clientAction;

    private Config config;

    private Map<String, Object> args;

    ClientHandleCreater() {
    }

    public ClientAction getClientAction() {
        return clientAction;
    }

    public ClientHandleCreater setClientAction(ClientAction clientAction) {
        this.clientAction = clientAction;
        return this;
    }

    public Config getConfig() {
        return config;
    }

    public ClientHandleCreater setConfig(Config config) {
        this.config = config;
        return this;
    }

    public Map<String, Object> getArgs() {
        return args == null ? new HashMap<>() : args;
    }

    public ClientHandleCreater setArgs(Map<String, Object> args) {
        this.args = args;
        return this;
    }

    public ClientHandle create() {
        if (clientAction == null) {
            throw new IllegalAccessError("clientAction is null");
        }
        
        ClientHandle handle = new ClientHandle();

        handle.config = config;
        handle.module = clientAction.getModule();
        handle.action = clientAction.getAction();
        handle.args = getArgs();
        
        return handle;
    }
}
